package com.gym.myshop.services.impl;

import com.gym.myshop.common.Pages;
import com.gym.myshop.dao.ProductDao;
import com.gym.myshop.dao.impl.ProductDaoImpl;
import com.gym.myshop.entity.Product;
import com.gym.myshop.services.ProductServices;
import com.gym.myshop.util.DBUtil;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author ming
 * 2021/11/6
 * description:
 */
public class ProductServicesImpl implements ProductServices {
    private ProductDao pd = new ProductDaoImpl();

    /**
     *@author:ming
     *@Date: 2021/11/6
     *@description:页面数据跳转
     */
    @Override
    public Map<String, Object> getProByPage(Integer tid, Integer pageIndex, int pageSize) {
        Map<String, Object> maps = null;
        try {
            DBUtil.begin();
            int count = pd.getCount(tid).intValue();
            Pages p = new Pages(pageIndex, pageSize, count);
            List<Product> proByPage = pd.getProByPage(tid, p.getStartRow(), p.getPageSize());
            maps = new HashMap<>();
            maps.put("list", proByPage);
            maps.put("page", p);
            DBUtil.commit();
        } catch (Exception e) {
            e.printStackTrace();
            DBUtil.rollback();
        }
        return maps;
    }


    /**
     *@author:ming
     *@Date: 2021/11/6
     *@description:商品序号找每个商品的种类详情
     */
    @Override
    public Product getProById(Integer pid) {
        try {
            DBUtil.begin();
            Product pro = pd.getProByIdWithType(pid);
            DBUtil.commit();
            return pro;
        } catch (Exception e) {
            e.printStackTrace();
            DBUtil.rollback();
        }
        return null;
    }
}
